package com.situ.Servlet.Test;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class AJaxServlet1 extends HttpServlet {
	/*doGet请求*/
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("AJaxServlet1.doGet()");
		String name = req.getParameter("name");//拿到ajax要传输到服务器的数据
		String age = req.getParameter("age");
		System.out.println("name : " + name);
		System.out.println("age : " + age);
		
		resp.setContentType("text/html;charset=utf-8");  //服务器返回给页面的，即在页面上弹出的数据
		resp.getWriter().write("{\"name\" : \"李四\",\"age\" : \"25\"}");
	}
	
	/*doPost请求*/
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("AJaxServlet1.doPost()");
		String name = req.getParameter("name");//拿到ajax要传输到服务器的数据
		String age = req.getParameter("age");
		System.out.println("name : " + name);
		System.out.println("age : " + age);
		
		resp.setContentType("text/html;charset=utf-8");  //服务器返回给页面的，即在页面上弹出的数据
		resp.getWriter().write("{\"name\" : \"李五\",\"age\" : \"23\"}");
	}
	
}
